<?php

namespace App\Aop;

use Psr\Log\LoggerInterface;
use Ray\Aop\MethodInterceptor;
use Ray\Aop\MethodInvocation;
use Symfony\Component\HttpFoundation\Session\Session;
use Wonfu\Http\ServerRequest;
use DI\Annotation\Inject;

class RequestInit implements MethodInterceptor
{
    /**
     * @Inject
     * @var ServerRequest
     */
    private $request;

    /**
     * @Inject
     * @var LoggerInterface
     */
    private $logger;

    public function invoke(MethodInvocation $invocation)
    {
        //log request
        $this->logger->info('client request...', [
            'content' => $this->request->getContent(),
            'uri' => $this->request->getPathInfo(),
            'query' => $this->request->getQueryParams()
        ]);
        //init session
        $session = new Session();
        $this->request->setSession($session);
        return $invocation->proceed();
    }


}